package logic

import (
	"context"
	"gorm.io/gorm"
	"local-life/models/mysql"

	"local-life/liferpc/internal/svc"
	"local-life/liferpc/liferpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *liferpc.OrderListRequest) (*liferpc.OrderListResponse, error) {
	// todo: add your logic here and delete this line

	order := mysql.Orders{
		Model: gorm.Model{ID: uint(in.OrderId)},
	}
	mysql.DB.Debug().Find(&order)

	return &liferpc.OrderListResponse{
		ShopId:     int64(order.ShopId),
		OrdersItem: order.OrdersItem,
		OrdersNum:  int64(order.OrdersNum),
	}, nil
}
